
import 'package:bottom_sheet_flutter/utils/color_util/color_util.dart';
import 'package:bottom_sheet_flutter/utils/style_util/style_util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../text_widget/text_widget.dart';

/// @className : action_bottom_sheet
/// @date 2022/07/18 17:12
/// @author : xiaohai
/// @description : 动作抽屉层

class ActionBottomSheetWidget extends StatefulWidget {
  ActionBottomSheetWidget(
      {Key? key, required this.actionItemList, this.actionItemEvent})
      : super(key: key);

  /// action列表
  final List<String?> actionItemList;

  /// actionItem点击事件
  Function(String? title, int index)? actionItemEvent;

  @override
  _ActionBottomSheetWidgetState createState() =>
      _ActionBottomSheetWidgetState();
}

class _ActionBottomSheetWidgetState extends State<ActionBottomSheetWidget> {
  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
        child: Column(
      children: [
        buildActionListWidget(),
        Container(
            height: 16.w,
            decoration: BoxDecoration(color: ColorsUtil.hexColor(0xF5F5F5))),
        buildCanceWidget(),

        /// 底部安全区域
        SizedBox(height: ScreenUtil().bottomBarHeight)
      ],
    ));
  }

  /// 构建ActionList组件
  Widget buildActionListWidget() {
    return MediaQuery.removePadding(
        context: context,
        removeBottom: true,
        child: ListView.builder(
            //内容适配
            shrinkWrap: true,
            scrollDirection: Axis.vertical,
            itemCount: widget.actionItemList.length,
            itemBuilder: (BuildContext context, int index) {
              String? titleStr = widget.actionItemList[index];
              return buildActionListItemWidget(titleStr, index);
            }));
  }

  /// 构建ActionListItem组件
  Widget buildActionListItemWidget(String? title, int index) {
    return InkWell(
      onTap: () {
        Navigator.pop(context);

        /// ActionItem点击事件
        widget.actionItemEvent!(title!, index);
      },
      child: Container(
        child: Column(children: [
          index != 0
              ? Container(color: ColorsUtil.hexColor(0xEBEDF2), height: 1.w)
              : const SizedBox(),
          Container(
              alignment: Alignment.center,
              padding: EdgeInsets.symmetric(horizontal: 24.w),
              height: 94.w,
              child: textWidget(title, TS_272133_36_W4)
    ),
        ]),
      ),
    );
  }

  /// 构建取消按钮
  Widget buildCanceWidget() {
    return InkWell(
      onTap: () {
        // 取消点击事件
        Navigator.pop(context);
      },
      child: Container(
          alignment: Alignment.center,
          padding: EdgeInsets.symmetric(horizontal: 24.w),
          height: 94.w,
          child: textWidget("取消", TS_272133_36_W4)),
    );
  }
}
